# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgbase=readline
pkgname=('libreadline' 'libreadline-devel')
_basever=6.3
_patchlevel=008 #prepare for some patches
pkgver=${_basever}.${_patchlevel}
pkgrel=6
pkgdesc="GNU readline library"
arch=('i686' 'x86_64')
url="http://tiswww.case.edu/php/chet/readline/rltop.html"
license=('GPL')
makedepends=('ncurses-devel')
#backup=('etc/inputrc')
options=('!emptydirs')
source=(http://ftp.gnu.org/gnu/readline/readline-$_basever.tar.gz{,.sig}
        readline-6.3-cygwin.patch
        readline-6.3-msys2.patch)
if [ $_patchlevel -gt 00 ]; then
    for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
        source=(${source[@]} http://ftp.gnu.org/gnu/readline/readline-${_basever}-patches/readline${_basever//./}-$(printf "%03d" $p){,.sig})
    done
fi
md5sums=('33c8fb279e981274f485fd91da77e94a'
         'SKIP'
         'f31ee9a5c41cee11c0dda1c13203dac9'
         '303e24bd011e0f812a268b4d84e19bd6'
         '4343f5ea9b0f42447f102fb61576b398'
         'SKIP'
         '700295212f7e2978577feaee584afddb'
         'SKIP'
         'af4963862f5156fbf9111c2c6fa86ed7'
         'SKIP'
         '11f9def89803a5052db3ba72394ce14f'
         'SKIP'
         '93721c31cd225393f80cb3aadb165544'
         'SKIP'
         '71dc6ecce66d1489b96595f55d142a52'
         'SKIP'
         '062a08ed60679d3c4878710b3d595b65'
         'SKIP'
         'ee1c04072154826870848d8b218d7b04'
         'SKIP')

prepare() {
  cd ${srcdir}/${pkgbase}-${_basever}
  for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
    msg "applying patch readline${_basever//./}-$(printf "%03d" $p)"
    patch -p0 -i $srcdir/readline${_basever//./}-$(printf "%03d" $p)
  done
  patch -p1 -i $srcdir/readline-6.3-cygwin.patch
  patch -p1 -i $srcdir/readline-6.3-msys2.patch
}

build() {
  cd ${srcdir}/${pkgbase}-${_basever}

  # Remove RPATH from shared objects (FS#14366)
  sed -i 's|-Wl,-rpath,$(libdir) ||g' support/shobj-conf

  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --host=${CHOST} \
    --with-curses \
    bash_cv_termcap_lib=libncurses
  make VERBOSE=1

  make DESTDIR=${srcdir}/dest install
}

package_libreadline() {
  depends=('ncurses')
  groups=('libraries')
  install=readline.install

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libreadline-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("libreadline=${pkgver}" 'ncurses-devel')
  pkgdesc="readline headers and libraries"

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
